<?php
class IndexAction extends GlobalAction{
	public function index(){
		$news = M('news');
		$news = $news->where("show_m = '1'")->limit('0,10')->order('news_id asc')->findall();
	    $this->assign('news',$news);
	    $project = M('channel');
	    $project = $project->where("partid = '1'")->limit('0,4')->findall();
	    $this->assign('project',$project);
	    $link = M('link');
	    $link = $link->where("show_m = '1'")->limit('0,4')->findall();
	    $this->assign('link',$link);
		$this->GlobalName();
		$this->display();
	}
	public function proflie(){
		$proflie = M('proflie');
		$this->GlobalName();
		$pid = $_GET['pid'];
		if(empty($_GET['pid'])){
			$pid = $proflie->getField('proflie_id');
		}
		$this->channel_list('1');
		$list = $proflie->where("show_m = '1'")->findall();
		$one = $proflie->where("proflie_id = $pid")->findall();
		$this->assign('list',$list);
		$this->assign('proflie',$one);
		$this->news_list();
		$this->display();
	}
	public function info(){
		
		$this->news_list();
		$info = M('info');
		$this->GlobalName();
		$infoid = $_GET['infoid'];
		if(empty($_GET['infoid'])){
			$infoid = $info->getField('info_id');
		}
		$list = $info->where("show_m = '1'")->findall();
		$one = $info->where("info_id = $infoid")->findall();
		$this->assign('list',$list);
		$this->assign('info',$one);
		$this->display();
	}
	public function job(){
		$this->info_list();
		$this->news_list();
		$this->GlobalName();
		$job = M('job');
		import("@.ORG.Page"); //导入分页类
	    $count = $job->where("show_m = '1'")->count();    //计算总数
	    $p = new Page($count,10);
	    $list = $job->where("show_m = '1'")->limit($p->firstRow.','.$p->listRows)->order('job_id asc')->findall();
		$page = $p->show();
	    $this->assign( "page",$page );
	    $this->assign('job',$list);
		$this->display();
	}
	public function job_detail(){
		$this->info_list();
		$this->news_list();
		$jid = $_GET['jid'];
		$job = M('job');
		$job = $job->where('job_id = '.$jid)->findall();
		$this->assign('job',$job);
		$this->GlobalName();
		$this->display();
	}
	public function services(){
		$this->info_list();
		$this->GlobalName();
		$this->display();
	}
	public function package(){
		$this->info_list();
		$this->GlobalName();
		$this->display();
	}
	public function process(){
		$this->info_list();
		$this->GlobalName();
		$this->display();
	}
	public function feedback(){
		$this->news_list();
		$this->info_list();
		$this->GlobalName();
		$this->display();
	}
	public function feedback_get(){
	if (!isset($_COOKIE["user"]))
		{
		    setcookie("user","100",time()+1800);
			$feedback = M('feedback');
			$feedback->create();
			if($feedback->add()){
				$this->get_alert('感谢您的留言，我们会尽快给您回复！请耐心等候。');
				$this->Go2Url('./');
			}
		}
		else
		{
			$this->get_alert('您已经留言过了，请不要重复提交，请30分钟后再提交留言。');
		}
	}
	public function cooperation(){
		$this->info_list();
		$this->GlobalName();
		$this->display();
	}
	public function news(){
		$news = M('news');
		$news_sort = $news->where("show_m = '1'")->distinct('distinct')->Field('sort,e_sort')->findall();
		import("@.ORG.Page"); //导入分页类
		if (empty($_GET['sort'])) {
	        $count = $news->where("show_m = '1' and top = '0'")->count();    //计算总数
	        $p = new Page ( $count, 10 );
	    	$list = $news->where("show_m = '1' and top = '0'")->limit($p->firstRow.','.$p->listRows)->order('news_id asc')->findall();
		}else{
			$count = $news->where("sort = '".$_GET['sort']."' and show_m = '1' and top = '0'")->count();    //计算总数
	        $p = new Page ( $count, 10 );
	    	$list = $news->where("sort = '".$_GET['sort']."' and show_m = '1' and top = '0'")->limit($p->firstRow.','.$p->listRows)->order('news_id asc')->findall();
		}
		$page = $p->show ();
		$top = $news->where("show_m = '1' and top = '1'")->limit('0,3')->order('news_id asc')->findall();
		$this->assign('sort',$news_sort);
	    $this->assign( "page", $page );
	    $this->assign('top',$top);
	    $this->assign('list',$list);
		$this->GlobalName();
		$this->display();
	}
	public function news_detail(){
		$this->news_sort_list();
		$nid = $_GET['nid'];
		$news = M('news');
		$news = $news->where('news_id = '.$nid)->findall();
		$this->assign('news',$news);
		$this->GlobalName();
		$this->display();
	}
	public function part(){
		$part = M('part');
		$this->GlobalName();
		$this->display();
	}
	public function channel(){
		$channel = M('channel');

		$this->GlobalName();
		$this->display();
	}
public function product(){
		$this->news_list();
		$product = M('product');
		$product_sort = $product->where("show_m = '1'")->distinct('distinct')->Field('sort,e_sort')->findall();
		import("@.ORG.Page"); //导入分页类
		if (empty($_GET['sort'])) {
	        $count = $product->where("show_m = '1'")->count();    //计算总数
	        $p = new Page ( $count, 12 );
	    	$list = $product->where("show_m = '1'")->limit($p->firstRow.','.$p->listRows)->order('product_id asc')->findall();
		}else{
			$count = $product->where("sortid = '".$_GET['sort']."' and show_m = '1'")->count();    //计算总数
	        $p = new Page ( $count, 12 );
	    	$list = $product->where("sortid = '".$_GET['sort']."' and show_m = '1'")->limit($p->firstRow.','.$p->listRows)->order('product_id asc')->findall();
		}
		$page = $p->show ();
		$this->assign('sort',$product_sort);
	    $this->assign( "page", $page );
		$picture = M('product_picture');
		for($i=0;$i<count($list);$i++){
			
			$picture_one = $picture->where("pid = '".$list[$i]['product_id']."' and defaultpic = '1'")->find();
			if(isset($picture_one)){
				$list[$i]['picture'] = 'Public/Uploads/s_'.$picture_one['photourl'];
			}else{
				$list[$i]['picture'] = 'Public/none.jpg';
			}
		}
	    $this->assign('list',$list);
		$this->product_sort_list();
		$this->GlobalName();
		$this->display();
	}
	public function product_detail(){
		$this->news_list();
		$this->product_sort_list();
		$id = $_GET['id'];
		$pic = M('product_picture');
		$pic_first = $pic->where("pid = '".$id."' and defaultpic = '1'")->getField('photourl');
		$this->assign('pic_first',$pic_first);
		$pic = $pic->where("pid = '".$id."'")->findall();
		
		$product = M('product');
		$product = $product->where("product_id = '".$id."'")->findall();
		
		$this->assign('pic',$pic);
		$this->assign('product',$product);
		$this->GlobalName();
		$this->display();
	}




	/***************************************************
	*
	* 小列表
	*
	***************/

	private function channel_list($pid){
		$channel = M('channel');
		$channel = $channel->where("partid = '$pid'")->limit('0,4')->findall();
		$this->assign('channel_list',$channel);
	}
	private function news_sort_list(){
		$news = M('news');
		$news_sort = $news->where("show_m = '1'")->distinct('distinct')->Field('sort,e_sort')->findall();
		$this->assign('list',$news_sort);
	}
	private function news_list(){
		$news = M('news');
		$news_list = $news->where("show_m = '1'")->limit('0,5')->order('news_id asc')->findall();
		$this->assign('news',$news_list);
	}
	private function product_sort_list(){
		$sort = M('sort');
		$list = $sort->where("show_m = '1'")->findall();
		$this->assign('sort',$list);
	}
	private function info_list(){
		$info = M('info');
		$list = $info->where("show_m = '1'")->findall();
		$this->assign('list',$list);
	}
	private function proflie_list(){
		$info = M('proflie');
		$list = $info->where("show_m = '1'")->findall();
		$this->assign('list',$list);
	}
}
?>